package com.ccut.lc.service.Impl;

import com.ccut.lc.dao.UserMapper;
import com.ccut.lc.model.Order;
import com.ccut.lc.model.QueryVo;
import com.ccut.lc.model.User;
import com.ccut.lc.service.IUserService;
import com.ccut.lc.utils.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class UserService  implements IUserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public User login(String username, String password, String type) {
        User u = new User();
        u.setUsername(username);
        u.setPassword(password);
        return userMapper.login(u);
    }

    @Override
    public void registUser(User ul) {
        userMapper.registUser(ul);
    }

    @Override
    public User selUser(String uid) {
        return userMapper.selUser(uid);
    }

    @Override
    public void updateUser(User ul) {
        userMapper.updateUser(ul);
    }

    @Override
    public Page<User> selUserList(QueryVo queryVo) {
        queryVo.setStart((queryVo.getPage()-1)*queryVo.getRows());
        List<User> list =  userMapper.selUserList(queryVo);
        int total = userMapper.getTotal(queryVo);
        Page<User> page = new Page<>(total,queryVo.getPage(),queryVo.getRows(),list);
        return page;
    }

    @Override
    public void delUser(String uid) {
        userMapper.delUser(uid);
    }
}
